﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace Brilliant.ORM
{
    /// <summary>
    /// 数据库事务处理
    /// </summary>
    public class DBTrans
    {
        /// <summary>
        /// 事务连接
        /// </summary>
        public DbConnection Conn { get; set; }

        /// <summary>
        /// 事务指令执行对象
        /// </summary>
        public DbCommand Cmd { get; set; }

        /// <summary>
        /// 事务对象
        /// </summary>
        public DbTransaction Trans { get; set; }

        /// <summary>
        /// 关闭连接释放资源
        /// </summary>
        public void Close()
        {
            if (Conn.State != ConnectionState.Closed || Conn != null)
            {
                Conn.Close();
                Conn.Dispose();
            }
        }

        /// <summary>
        /// 提交事务
        /// </summary>
        public void Commit()
        {
            Trans.Commit();
        }

        /// <summary>
        /// 回滚事务
        /// </summary>
        public void Rollback()
        {
            Trans.Rollback();
        }
    }
}
